module.exports = {
  currentPage: null,
  init: function(e, t) {
      this.currentPage = e;
      var o = this;
      void 0 === e.jiaMch && (e.jiaMch = function (ee) {
        o.jiaMch(ee);
      }),void 0 === e.jianMch && (e.jianMch = function (ee) {
        o.jianMch(ee);
      }),void 0 === e.clearCarMch && (e.clearCarMch = function (ee) {
        o.clearCarMch(ee);
      })
  },
  jiaMch:function (t) { console.log(t);
    var a = this.currentPage, o = t.currentTarget.dataset;
    var d = a.data.carGoods, c = 1, n = o.price ,index=o.index;
    for (var u in d) {
        if (parseInt(d[u].goods_id) === parseInt(o.id) && index == u) {
            var e = d[u].num ? d[u].num+1 : 1
            d[u].num = e, d[u].goods_price = (d[u].num * d[u].price).toFixed(2);
            break;
        }
    }
    a.setData({
        carGoods: d,
    }), a.carStatistics();
  },
  jianMch:function (t) { console.log(t);
    var a = this.currentPage, o = t.currentTarget.dataset;
    var d = a.data.carGoods, c = 1, n = o.price ,index=o.index;
    for (var u in d) {
        if (parseInt(d[u].goods_id) === parseInt(o.id) && index == u) {
            var e = d[u].num>1 ? d[u].num-1 : 0
            d[u].num = e, d[u].goods_price = (d[u].num * d[u].price).toFixed(2);
            break;
        }
    }
    a.setData({
        carGoods: d,
    }), a.carStatistics();
  },
  carStatistics: function() {
      var t = this.currentPage, a = t.data.carGoods;
      wx.setStorageSync('mch_cat_goods_' + t.data.goods.mch.id, a)
      var o = 0, r = 0;
      for (var i in a) o += a[i].num, r = parseFloat(r) + parseFloat(a[i].goods_price);
      var s = {
          total_num: o,
          total_price: r.toFixed(2)
      };
      0 === o , t.setData({
          total: s
      });
  },
  clearCarMch: function(t) {
    var a = this.currentPage,mch_id=a.data.goods.mch ? a.data.goods.mch.id : 0;
    a.setData({
        carGoods: [],
        goodsModel: !1,
        total: {
            total_num: 0,
            total_price: 0
        },
        check_num: 0,
        currentGood: [],
        checked_attr: [],
        check_goods_price: 0,
        temporaryGood: {}
    }), console.log('mch_cat_goods_' + mch_id) ,wx.removeStorageSync('mch_cat_goods_' + mch_id);
},
};